package com.wendal.java.vfilesystem;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;

public class SynchronizedVFileSystem implements IFileSystem {
	
	private VFileSystem fileSystem;
	
	public SynchronizedVFileSystem(File dataFile, int size, int blockSize)
		throws FileNotFoundException {
		fileSystem = new VFileSystem(dataFile,size,blockSize);
	}

	@Override
	public void add(String key, Serializable serializable) throws IOException {
		synchronized (fileSystem) {
			fileSystem.add(key, serializable);
		}
	}

	@Override
	public Serializable read(String key) throws IOException,
			ClassNotFoundException {
		synchronized (fileSystem) {
			return fileSystem.read(key);
		}
	}

	@Override
	public void remove(String key) {
		synchronized (fileSystem) {
			fileSystem.remove(key);
		}
	}

	@Override
	public void reset() throws IOException {
		synchronized (fileSystem) {
			fileSystem.reset();
		}
	}
	
	@Override
	public VFileIndex getCurrentVFileIndex() {
		synchronized (fileSystem) {
			return fileSystem.getCurrentVFileIndex();
		}
	}
}
